package com.suxg.hbase.mapper;

import java.util.Map;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import com.suxg.hbase.api.RowMapper;
import com.suxg.hbase.model.StudentModel;

public class StudentMapper implements RowMapper<StudentModel> {
	private static byte[] COLUMN_FAMILY = "student".getBytes();
	private static byte[] NAME = "name".getBytes();
	private static byte[] AGE = "age".getBytes();
	private static byte[] GENDER = "gender".getBytes();

	@Override
	public StudentModel mapRow(Result result, int rowNum,Map<byte[], byte[]> familyMap) {
 
		 for(Map.Entry<byte[], byte[]> entry:familyMap.entrySet()){
			 
		        System.out.println(Bytes.toString(entry.getKey())+"=====>"+Bytes.toString(entry.getValue()));
		    }
		
		String name = Bytes.toString(result.getValue(COLUMN_FAMILY, NAME));
		String age = Bytes.toString(result.getValue(COLUMN_FAMILY, AGE));
		String gender = Bytes.toString(result.getValue(COLUMN_FAMILY, GENDER));
		StudentModel sdm = new StudentModel();
		sdm.setName(name);
		//判断不为null，“” ，” “
		if(StringUtils.hasText(age)) {
		sdm.setAge(Integer.valueOf(age));
		}
		sdm.setGender(gender);
		return sdm;
	}

}
